#include "inversegammanode.h"
#include "gsl/gsl_specfunc.h"

InverseGammaNode::InverseGammaNode(double val) :
        GammaNode(val)
{}


InverseGammaNode::InverseGammaNode(QString label, double val, double sd, Node * alphaNode, Node * betaNode, bool isObserved) :
        GammaNode(label, val, sd, alphaNode, betaNode, isObserved)
{}

bool InverseGammaNode::inRange(double v)
{
    return 0.0 < v;
}

/*double InverseGammaNode::getValue()
{
    return 1.0 / Node::getValue();
}

double InverseGammaNode::generateSample()
{
    return 1.0 / Node::generateSample();
}*/


double InverseGammaNode::computeLogLikelihood()
{      
    double a = parents->at(alphaNode)->getValue();
    double b = parents->at(betaNode)->getValue();
    double v = this->getValue();

    return a * log(b) - gsl_sf_lngamma(a) + (-a-1) * log(v) - b/v;
}
